package iscript.gameFramework.GameLite.content 
{
	import flash.utils.Dictionary;
	import flash.utils.getQualifiedClassName;
	import iscript.gameFramework.GameLite.core.GameComponent;
	import iscript.gameFramework.GameLite.events.GameContentEvent;

	internal class ComponentContent implements IGameContent
	{
		private var _data:Dictionary = new Dictionary();
		private var _gameContent:GameContent
		
		public function ComponentContent(gameContent:GameContent) 
		{
			_gameContent = gameContent;
		}
		
		
		//public function get KEY():Array { return _data.getAllKeys() }	
		
		public function add(comp:GameComponent):void
		{
			var key:String =  getQualifiedClassName(comp).split( "::" ).join( "." );
			if(_data[key]==null){
					_data[key] = comp;
				   var event:GameContentEvent = new GameContentEvent(GameContentEvent.ADDCOMPONENT);
				       event.key = key;
					   event.content = comp;
					   _gameContent.dispatchEvent(event);
				
				   var e:GameContentEvent = new GameContentEvent(GameContentEvent.EVERYTHING)
					   e.key = key;
					   e.content = comp;
					   _gameContent.dispatchEvent(e);	   
			 
		   }
		}
		
		public function get(key:*):GameComponent
		{
			return _data[key];
		}
		
		public function contain(key:*):Boolean {
			  return  _data[key] != null;
		}
		
		public function remove(key:*):void
		{
			delete _data[key];
		}
		
	}

}